// Int array sort using pointers
// Date 23:37 25/10/2016
// By Ben a.k.a DreamVB

#include <iostream>
using namespace std;
using std::cout;
using std::endl;

void Display(int *d, int size){
	int *ptr = d;
	int i = 0;
	while (i < size){
		//Print out the item using the address of the array contents
		cout << *ptr << " ";
		*ptr++;
		i++;
	}
	cout << endl;
}

void MySort(int *d, int size){
	int i = 0;
	int j = 0;
	int t = 0;
	//Simple sort of int array using pointers
	for (i = 0; i < size; i++){
		for (j = i + 1; j < size; j++){
			if (*(d+i) > *(d+j)){
				t = *(d + j);
				*(d + j) = *(d + i);
				*(d + i) = t;
			}
		}
	}
}

int main(int argc, char *argv[]){
	int nums[6] = { 60, 30, 50, 20, 10,40 };

	int len = sizeof(nums) / sizeof(int);

	cout << "P O I N T E R S  -  D E M O" << endl;

	cout << "Original : ";
	Display(nums, len);

	MySort(nums, len);

	cout << "Sorted using pointers : ";
	Display(nums, len);

	system("pause");
	return 0;
}